﻿<!doctype html>
<html><!-- InstanceBegin template="/Templates/template1.dwt" codeOutsideHTMLIsLocked="false" -->
<head>
<meta charset="utf-8">
<!-- InstanceBeginEditable name="doctitle" -->
<title>优惠券使用统计</title>
<!-- InstanceEndEditable -->
<script type="text/javascript" src="../js/common.js"></script>
<!--<script type="text/javascript" src="../js/sub.js"></script> 标签切换 -->
	<script type="text/javascript" src="../js/utils.js"></script>
<script type="text/javascript" src="../js/highstock.js"></script>
<script type="text/javascript" src="../js/exporting.js"></script>
	<script type="text/javascript" src="../js/utils.js"></script>
	<script type="text/javascript" src="../js/checkLogin.js"></script>
<link href="../css/style.css" type="text/css" rel="stylesheet" />

<!-- InstanceBeginEditable name="head" -->
<!-- InstanceEndEditable -->
<script type="text/javascript">	
			
			$(document).ready(function() {
						$.ajax({
						type : "get",
						datatype : "json",
						url : "../memberConpCsm/find/deositCsSum",
						success : function(data) {
							var rst = JSON.parse(data);
							DealAndShowMsg(data,false,false);

								if(rst.state==0){
									$("#allCount").html(rst.result.data[0][0])
								 	$("#yesCount").html(rst.result.data[0][1])
									}
						}	
					});
						var now=new Date();
						endTime=now.getFullYear()+"-"+(now.getMonth()+1)+"-"+now.getDate();
						$("#dtEnd").val(endTime)	
						now.setTime(now.getTime()-30*24*3600*1000);
						beginTime=now.getFullYear()+"-"+(now.getMonth()+1)+"-"+now.getDate();
						$("#dtBegin").val(beginTime)	
				findMemberCount(1)
			});
			
			
			function findMemberCount(type){
			
				var beginTime=$("#dtBegin").val();
				var endTime = $("#dtEnd").val();
				var param="timeBegin="+beginTime+"&timeEnd="+endTime;
				$.ajax({
						type : "get",
						async:false,
						data:param,
						datatype : "json",
						url : "../memberConpCsm/find/memberCCsmSum",
						success : function(data) {
							var rst = JSON.parse(data);
										if(IsEmpty(rst)){
											art.dialog({fixed:true, lock: true,content:"查询错误",icon:'error',ok:true});	
											return false;
											}
											if(rst.state==0){
												if(beginTime==""){
													beginTime=rst.result.data[0][0]
													$("#dtBegin").val(beginTime)
												}
												
												if(endTime==""){
													var now=new Date();
													endTime=now.getFullYear()+"-"+(now.getMonth()+1)+"-"+now.getDate()
													$("#dtEnd").val(endTime)
													}
										$("#memberList1 tbody ").empty();
										if(type==1){
											
										makeParam(rst,beginTime,endTime);
										}else{
										makeAllParam(rst,beginTime,endTime)	
										}	
										}else if(rst.state==1){
										art.dialog({fixed:true, lock: true,content:rst.msg,icon:'error',ok:true});	
										}else{
												checkStateShowErrorMsgAndDealResult(data);
										}			
										
										
						}	
					});
				
			}
			
			function makeAllParam(json,begin,end){
			begin = begin.replace(/-/g,"/");
			var date = new Date(begin );
			var end=new Date(end.replace(/-/g,"/"))
			
			var time=[]
			var j=0;
			while(date<end){
				time[j]=date.toDateString();
				date.setDate(date.getDate()+1)
						j++;
			}
			var dt=json.result.data
			var param=[];
			var currc=0;
			var value=0;
			var timeV=null;
			for(m=0;m<time.length;m++){
				var x=new Date(time[m]);
				var xm=[];
				xm[0]=Date.UTC(x.getFullYear(), x.getMonth(), x.getDate())
				for(i=0;i<dt.length;i++){
					 timeV=new Date(dt[i][0].replace(/-/g,"/"))
					
					if(timeV.toDateString()==time[m]){
						value+=dt[i][1]
						currc=dt[i][1]
					}
				}	
				
				
							
					xm[1]=value
					param[m]=xm
					$("#memberList1 tbody ").prepend("<tr></tr>");
					
					$("#memberList1 tbody tr:first").append("<td>"+x.getFullYear()+"-"+(x.getMonth()+1)+"-"+x.getDate()+"</td>").append("<td>"+currc+"</td>").append("<td>"+value+"</td>");
					currc=0;
			}
			highChars(param,"累计返利","累计：");
		}
			function makeParam(json,begin,end){
			
				begin = begin.replace(/-/g,"/");
				var date = new Date(begin );
				var end=new Date(end.replace(/-/g,"/"))
				
				var time=[]
				var j=0;
				while(date<end){
					time[j]=date.toDateString();
					date.setDate(date.getDate()+1)
							j++;
				}
				var dt=json.result.data
				var param=[];
				var count=0;
				var value=0;
				var timeV=null;
				for(m=0;m<time.length;m++){
					var x=new Date(time[m]);
					var sx=[];
					sx[0]=Date.UTC(x.getFullYear(), x.getMonth(), x.getDate());
					for(i=0;i<dt.length;i++){
						 timeV=new Date(dt[i][0].replace(/-/g,"/"))
						
						if(timeV.toDateString()==time[m]){
					
							value=dt[i][1];
						}
					}
						if(value>0){
							sx[1]=value;
							count+=value
							value=0;
						}else{
						sx[1]=null;
						}
						param[m]=sx;
						
						$("#memberList1 tbody ").prepend("<tr></tr>");
						
						$("#memberList1 tbody tr:first").append("<td>"+x.getFullYear()+"-"+(x.getMonth()+1)+"-"+x.getDate()+"</td>").append("<td>"+(sx[1]==null?0:sx[1])+"</td>").append("<td>"+count+"</td>");
							
				}
				
				highChars(param,"优惠劵使用统计","使用金额：");
			}
			
			function highChars(param,title,name){//绘图
			 var s=	new Highcharts.StockChart({
					chart: {
						renderTo: 'container1',
						marginRight: 30,
						marginBottom: 25
					},
				 credits:{
					 enabled :false
				 },
				 
					exporting:{
						enabled:false,
						show:false
					},
					rangeSelector: {
						show:false,
						enable:true,
				        buttons: [{
				            type: 'day',
				            count: 3,
				            text: '3天'
				        }, {
				            type: 'week',
				            count: 1,
				            text: '1周'
				        }, {
				            type: 'month',
				            count: 1,
				            text: '1个月'
				        }, {
				            type: 'month',
				            count: 6,
				            text: '6个月'
				        }, {
				            type: 'year',
				            count: 1,
				            text: '1年'
				        }, {
				            type: 'all',
				            text: '所有'
				        }],
				        selected: 6
				    },
					title: {
						text: title
						
					},
					subtitle: {
						text: ''
						
					},
					xAxis:{
			            labels: {  
			            formatter: function() {  
			                var vDate=new Date(this.value);  
			                return (vDate.getMonth()+1)+"-"+vDate.getDate();  
			            },
			            maxStaggerLines:3
						},
						minRange:7*24*3600*1000
						},
					yAxis: {
						title: {
							text: ''
						},
						plotLines: [{
							value: 0,
							width: 1,
							color: '#808080'
						}],
						min:0
					},
					 tooltip: {  
				            xDateFormat: '%Y-%m-%d'//鼠标移动到趋势线上时显示的日期格式  
				        },  
					legend: {
						layout: 'vertical',
						align: 'right',
						verticalAlign: 'top',
						x: -10,
						y: 100,
						borderWidth: 0
					},
					series: [{
						name: name,
						data: param,
						 pointInterval: 24*3600 * 1000,
					        tooltip: {
					        	valueSuffix: '元'
					        }
					}]
				});
			 	
			}
				
		</script>
</head>

<body>
<!-- InstanceBeginEditable name="EditRegion3" -->
<script type="text/javascript" src="../js/doubleDate2.0.js"></script>
<script type="text/javascript">
$(function(){
	
	$('.doubledate').kuiDate({
		className:'doubledate',
		isDisabled: "0"  // isDisabled为可选参数，“0”表示今日之前不可选，“1”标志今日之前可选
	});
	$("#sub_s1").click(function(){
		findMemberCount(1)
		$("#search_btn2").hide()
		$("#search_btn1").show();
		$(this).addClass("focus");
		$("#sub_s2").removeClass("focus");
	})
	$("#sub_s2").click(function(){
		findMemberCount(2)
		$("#search_btn1").hide()
		$("#search_btn2").show();
		$(this).addClass("focus");
		$("#sub_s1").removeClass("focus");
	})

});
</script>
<script type="text/javascript" src="../js/sub.js"></script>
<div class="container" id="container">
  <div class="container_R fr">
	<div class="place">优惠券使用统计</div>
	<div class="shadow yesterday_all">
    	<h2 class="title">昨日指标</h2>
        <ul class="main_number">
        	<li class="noBorder"><strong>新使用</strong><span id="yesCount"></span></li>
        	<li><strong>总计</strong><span id="allCount"></span></li>
        </ul>
        <div class="fc"></div>
    </div>
    <div class="shadow yesterday_all" id="bigBox">
    	<h2 class="title">关键指标详解<div id="sub"><span class="focus" id="sub_s1">优惠劵使用</span><span id="sub_s2">优惠劵累计使用</span></div></h2>
    	<div class="search_term"><span>起始日期：</span><input type="text" readonly class="doubledate ipticon"  id="dtBegin"/><span>截止时间：</span><input type="text" readonly class="doubledate ipticon" id="dtEnd"/><input type="button" id="search_btn1" class="search_btn common_btn" onclick="findMemberCount(1)" value="查询"><input type="button" id="search_btn2" style="display: none;" class="search_btn common_btn" onclick="findMemberCount(2)" value="查询"></div>
        	<div class="box_img">
            	<h4>趋势图</h4>
                <div class="line_img"> <div id="container1"></div> </div>
            </div>   
        	 <div>
           <table  width="100%" class="member_list" cellpadding="0" cellspacing="1" border="0" id="memberList1">
    	<thead>
    	<tr>
        	<th>日期</th>
        	<th>优惠劵使用</th>
        	<th>累计使用</th>
        </tr>
        </thead>
    	<tbody></tbody>
    </table>
          </div>   
    </div>
  </div>
  <div class="fc"></div>
</div>

<!-- InstanceEndEditable -->
<script type="text/javascript" src="../js/header.js"></script>
<script type="text/javascript" src="../js/left.js"></script>
<script type="text/javascript" src="../js/footer.js"></script>
<script type="text/javascript">
showTab(9,3);
</script>
</body>
<!-- InstanceEnd --></html>
